package com.cn.por.util.json;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonExample {

    public static void main(String[] args) {
        JSONObject jsonObject = JSONUtil.parseObj("{\"tooltip\":{\"trigger\":\"axis\",\"confine\":true,\"axisPointer\":{\"type\":\"shadow\"}}}");

        System.out.println(JSONUtil.toJsonStr(jsonObject));
        String jsonString = "{\"1\": [{\"text_lines\": [{\"polygon\": [[900.0, 33.0], [1157.0, 38.0], [1156.0, 81.0], [900.0, 76.0]], \"confidence\": 0.6988857984542847, \"text\": \".il! xi! ♥ (54)\", \"bbox\": [900.0, 33.0, 1157.0, 81.0]}, {\"polygon\": [[51.0, 41.0], [262.0, 38.0], [262.0, 75.0], [52.0, 79.0]], \"confidence\": 0.8800050616264343, \"text\": \"5:03 \", \"bbox\": [51.0, 41.0, 262.0, 75.0]}, {\"polygon\": [[414.0, 142.0], [804.0, 146.0], [803.0, 202.0], [413.0, 198.0]], \"confidence\": 0.9778842329978943, \"text\": \"消息队列-Kafka\", \"bbox\": [414.0, 142.0, 804.0, 202.0]}, {\"polygon\": [[355.0, 268.0], [863.0, 266.0], [863.0, 313.0], [355.0, 315.0]], \"confidence\": 0.9934170246124268, \"text\": \"以下为您列出 60 道面试题\", \"bbox\": [355.0, 268.0, 863.0, 313.0]}, {\"polygon\": [[100.0, 344.0], [1076.0, 344.0], [1076.0, 391.0], [100.0, 391.0]], \"confidence\": 0.9770398139953613, \"text\": \"是会发现节点已经存在，此时会受到一个异常，此时\", \"bbox\": [100.0, 344.0, 1076.0, 391.0]}, {\"polygon\": [[100.0, 402.0], [1053.0, 404.0], [1053.0, 447.0], [100.0, 445.0]], \"confidence\": 0.9960958957672119, \"text\": \"就会在zookeeper中创建一个watch对象，方便这些\", \"bbox\": [100.0, 402.0, 1053.0, 447.0]}, {\"polygon\": [[99.0, 461.0], [665.0, 457.0], [666.0, 500.0], [99.0, 504.0]], \"confidence\": 0.9727316498756409, \"text\": \"broker接受leader的变更消息 ;\", \"bbox\": [99.0, 461.0, 665.0, 500.0]}, {\"polygon\": [[100.0, 515.0], [1059.0, 515.0], [1059.0, 558.0], [100.0, 558.0]], \"confidence\": 0.9960237145423889, \"text\": \"如果主leader因为网络问题与zookeeper断开连接或\", \"bbox\": [100.0, 515.0, 1059.0, 558.0]}, {\"polygon\": [[100.0, 566.0], [1064.0, 572.0], [1064.0, 620.0], [100.0, 614.0]], \"confidence\": 0.9867537617683411, \"text\": \"者发生异常退出了，其他的broker就可以通watch接\", \"bbox\": [100.0, 566.0, 1064.0, 620.0]}, {\"polygon\": [[100.0, 628.0], [1052.0, 624.0], [1052.0, 671.0], [100.0, 674.0]], \"confidence\": 0.98210608959198, \"text\": \"收到控制器的变更通知，开始尝试去创建临时节点/\", \"bbox\": [100.0, 628.0, 1052.0, 671.0]}, {\"polygon\": [[99.0, 683.0], [1082.0, 683.0], [1082.0, 728.0], [99.0, 728.0]], \"confidence\": 0.9923911094665527, \"text\": \"controller，如果有一个broker创建成功了，就和上面\", \"bbox\": [99.0, 683.0, 1082.0, 728.0]}, {\"polygon\": [[99.0, 740.0], [1114.0, 737.0], [1114.0, 783.0], [99.0, 785.0]], \"confidence\": 0.9966099858283997, \"text\": \"说的一样，其他的broker也会收到异常通知，此时就说\", \"bbox\": [99.0, 740.0, 1114.0, 783.0]}, {\"polygon\": [[100.0, 795.0], [1106.0, 795.0], [1106.0, 842.0], [100.0, 842.0]], \"confidence\": 0.9880209565162659, \"text\": \"明集群中broker的leader已经确定，其他的broker只能\", \"bbox\": [100.0, 795.0, 1106.0, 842.0]}, {\"polygon\": [[100.0, 855.0], [428.0, 851.0], [429.0, 892.0], [100.0, 896.0]], \"confidence\": 0.9718384146690369, \"text\": \"创建watch对象了\", \"bbox\": [100.0, 855.0, 428.0, 892.0]}, {\"polygon\": [[100.0, 903.0], [1066.0, 903.0], [1066.0, 953.0], [100.0, 953.0]], \"confidence\": 0.995955765247345, \"text\": \"集群中broker的leader发生异常退出，在选举出新的\", \"bbox\": [100.0, 903.0, 1066.0, 953.0]}, {\"polygon\": [[98.0, 965.0], [1107.0, 960.0], [1107.0, 1005.0], [98.0, 1010.0]], \"confidence\": 0.9859484434127808, \"text\": \"leader之后，会检测这个异常的broker上面是否有分区\", \"bbox\": [98.0, 965.0, 1107.0, 1005.0]}, {\"polygon\": [[100.0, 1018.0], [1103.0, 1018.0], [1103.0, 1065.0], [100.0, 1065.0]], \"confidence\": 0.9965546131134033, \"text\": \"副本的leader，如果有就是发起分区的leader选举，选\", \"bbox\": [100.0, 1018.0, 1103.0, 1065.0]}, {\"polygon\": [[100.0, 1077.0], [876.0, 1074.0], [876.0, 1118.0], [100.0, 1121.0]], \"confidence\": 0.9948770403862, \"text\": \"出新额分区leader，然后更新ISR队列数据\", \"bbox\": [100.0, 1077.0, 876.0, 1118.0]}, {\"polygon\": [[98.0, 1184.0], [446.0, 1186.0], [446.0, 1230.0], [98.0, 1229.0]], \"confidence\": 0.9826521277427673, \"text\": \"3. 触发leader选举\", \"bbox\": [98.0, 1184.0, 446.0, 1230.0]}, {\"polygon\": [[100.0, 1243.0], [1001.0, 1243.0], [1001.0, 1288.0], [100.0, 1288.0]], \"confidence\": 0.991042971611023, \"text\": \"现阶段的kakfa集群中，只需要broker的leader在\", \"bbox\": [100.0, 1243.0, 1001.0, 1288.0]}, {\"polygon\": [[100.0, 1297.0], [1103.0, 1302.0], [1102.0, 1347.0], [100.0, 1343.0]], \"confidence\": 0.9909983277320862, \"text\": \"zookeeper去注册相应的监听器，其他的broker很少去\", \"bbox\": [100.0, 1297.0, 1103.0, 1347.0]}, {\"polygon\": [[101.0, 1357.0], [1059.0, 1353.0], [1059.0, 1398.0], [101.0, 1403.0]], \"confidence\": 0.9977663159370422, \"text\": \"监听zookeeper的数据变化，但是每个broker还是需\", \"bbox\": [101.0, 1357.0, 1059.0, 1398.0]}, {\"polygon\": [[101.0, 1412.0], [1098.0, 1412.0], [1098.0, 1457.0], [101.0, 1457.0]], \"confidence\": 0.995171308517456, \"text\": \"要对/controller进行监听；当/controller节点发生数据\", \"bbox\": [101.0, 1412.0, 1098.0, 1457.0]}, {\"polygon\": [[100.0, 1468.0], [1076.0, 1468.0], [1076.0, 1513.0], [100.0, 1513.0]], \"confidence\": 0.9987163543701172, \"text\": \"变化的时候，每个broker都会更新自身内存中保存的\", \"bbox\": [100.0, 1468.0, 1076.0, 1513.0]}, {\"polygon\": [[100.0, 1529.0], [469.0, 1529.0], [469.0, 1567.0], [100.0, 1567.0]], \"confidence\": 0.9756230115890503, \"text\": \"activeControllerId。\", \"bbox\": [100.0, 1529.0, 469.0, 1567.0]}, {\"polygon\": [[101.0, 1576.0], [1107.0, 1576.0], [1107.0, 1625.0], [101.0, 1625.0]], \"confidence\": 0.9857693314552307, \"text\": \"当/controller节点被删除时，集群中的broker会进行选\", \"bbox\": [101.0, 1576.0, 1107.0, 1625.0]}, {\"polygon\": [[100.0, 1633.0], [1115.0, 1635.0], [1115.0, 1681.0], [100.0, 1679.0]], \"confidence\": 0.9985418915748596, \"text\": \"举，如果broker在节点被删除前是控制器的话，在选举\", \"bbox\": [100.0, 1633.0, 1115.0, 1681.0]}, {\"polygon\": [[102.0, 1691.0], [1120.0, 1691.0], [1120.0, 1736.0], [102.0, 1736.0]], \"confidence\": 0.9875625967979431, \"text\": \"前还需要有一个下线的操作（关闭相应的资源，比如关\", \"bbox\": [102.0, 1691.0, 1120.0, 1736.0]}, {\"polygon\": [[101.0, 1746.0], [1096.0, 1749.0], [1095.0, 1794.0], [101.0, 1792.0]], \"confidence\": 0.9953070282936096, \"text\": \"闭状态机、注销相应的监听器等）。如果有特殊需要，\", \"bbox\": [101.0, 1746.0, 1096.0, 1794.0]}, {\"polygon\": [[101.0, 1805.0], [1104.0, 1799.0], [1104.0, 1846.0], [101.0, 1852.0]], \"confidence\": 0.9957185983657837, \"text\": \"可以手动删除/controller节点来触发新一轮的选举。当\", \"bbox\": [101.0, 1805.0, 1104.0, 1846.0]}, {\"polygon\": [[100.0, 1861.0], [1105.0, 1861.0], [1105.0, 1904.0], [100.0, 1904.0]], \"confidence\": 0.9959307909011841, \"text\": \"然关闭控制器所对应的broker以及手动向/controller节\", \"bbox\": [100.0, 1861.0, 1105.0, 1904.0]}, {\"polygon\": [[102.0, 1918.0], [1092.0, 1913.0], [1093.0, 1959.0], [102.0, 1964.0]], \"confidence\": 0.9955528378486633, \"text\": \"点写入新的brokerid的所对应的数据同样可以触发新一\", \"bbox\": [102.0, 1918.0, 1092.0, 1959.0]}, {\"polygon\": [[100.0, 1972.0], [279.0, 1972.0], [279.0, 2014.0], [100.0, 2014.0]], \"confidence\": 0.9214596152305603, \"text\": \"轮的选举\", \"bbox\": [100.0, 1972.0, 279.0, 2014.0]}, {\"polygon\": [[320.0, 2107.0], [1110.0, 2105.0], [1110.0, 2157.0], [320.0, 2159.0]], \"confidence\": 0.9498383402824402, \"text\": \"此解析是否帮助到您？ \", \"bbox\": [320.0, 2107.0, 1110.0, 2157.0]}, {\"polygon\": [[62.0, 2349.0], [566.0, 2352.0], [566.0, 2395.0], [61.0, 2393.0]], \"confidence\": 0.9293236136436462, \"text\": \"₪ 33 . 简述什么是脑裂 ?\", \"bbox\": [62.0, 2349.0, 566.0, 2395.0]}, {\"polygon\": [[65.0, 2436.0], [346.0, 2436.0], [346.0, 2482.0], [65.0, 2482.0]], \"confidence\": 0.9290295839309692, \"text\": \"推荐指数 ★ ★\", \"bbox\": [65.0, 2436.0, 346.0, 2482.0]}, {\"polygon\": [[352.0, 2436.0], [528.0, 2436.0], [528.0, 2480.0], [352.0, 2480.0]], \"confidence\": 0.9232326745986938, \"text\": \"难度:中级\", \"bbox\": [352.0, 2436.0, 528.0, 2480.0]}, {\"polygon\": [[63.0, 2547.0], [560.0, 2547.0], [560.0, 2575.0], [63.0, 2575.0]], \"confidence\": 0.7789942026138306, \"text\": \"[…] [\", \"bbox\": [63.0, 2547.0, 560.0, 2575.0]}, {\"polygon\": [[989.0, 2555.0], [1139.0, 2555.0], [1139.0, 2572.0], [989.0, 2572.0]], \"confidence\": 0.49995917081832886, \"text\": \"//> <bit> <\", \"bbox\": [989.0, 2555.0, 1139.0, 2572.0]}], \"languages\": [\"zh\", \"en\"], \"image_bbox\": [0.0, 0.0, 1220.0, 2712.0], \"page\": 1}]}";

        try {
            // 初始化 ObjectMapper
            ObjectMapper mapper = new ObjectMapper();

            // 将 JSON 字符串转换为 JsonNode 对象
            JsonNode jsonNode = mapper.readTree(jsonString);
            JsonNode children = jsonNode.get("1").get(0).get("text_lines");
            boolean breakFlag = true;
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < children.size(); i++) {
                JsonNode item = children.get(0);
                String text = item.get("text")+"";
                if(text.startsWith("推荐指")){

                }
                if(!breakFlag){
                    sb.append(text+"\n");
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
